<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('工作记录列表')"/>
</head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <input id="deptId" name="deptId" type="hidden"/>
                    <ul>
                        <li>
                            <label>部门名称：</label>
                            <input type="text" onclick="selectDeptTree()" id="deptName" name="deptName" autocomplete="off"/>
                        </li>
                        <!--<li>-->
                            <!--销售名称：<input type="text" name="userName"/>-->
                        <!--</li>-->
                        <li>
                            客户名称：<input type="text" name="customerName"/>
                        </li>
                        <!--暂不提供检索，故此不需要选择统计周期维度-->
                        <li>
                            时间类型：
                            <select id="type" name="type">
                                <option value="">请选择</option>
                                <option value="day">日</option>
                                <option value="week">周</option>
                                <option value="month">月</option>
                                <option value="quarter">季</option>
                                <option value="year">年</option>
                            </select>
                        </li>
                        <li class="select-time">
                            <label>时间区间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始日期"
                                   name="startTime" autocomplete="off"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束日期"
                                   name="endTime" autocomplete="off"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="crm:work:export">
                <i class="fa fa-download"></i> 导出工作清单
            </a>
            <a class="btn btn-info" onclick="exportExcel()" shiro:hasPermission="crm:work:export">
                <i class="fa fa-download"></i> 导出统计报表
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <span>Tips：引领性指标报表导出请点击【导出统计报表】按钮，需要选择部门和时间范围！</span>
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    var prefix = ctx + "crm/work";

    $(function () {
        var options = {
            url: prefix + "/worklist",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "工作记录",
            search: false,
            showExport: false,
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'parentDeptName',
                    title: '部门名称',
                    sortable: false
                },
                {
                    field: 'deptName',
                    title: '小组名称',
                    sortable: false
                },
                {
                    field: 'time',
                    title: '时间',
                    sortable: false
                },
                {
                    field: 'call',
                    title: '电话',
                    sortable: false
                },
                {
                    field: 'visit',
                    title: '拜访',
                    sortable: false
                },
                {
                    field: 'call',
                    title: '提案',
                    sortable: false
                },
                {
                    field: 'sign',
                    title: '签约',
                    sortable: false
                }
                ]
        };
        $.table.init(options);
    });

    // 导出数据
    function exportExcel(formId) {
        let currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;

        $.modal.loading("正在导出数据，请稍后...");
        $.post(prefix + "/exportExcel", $("#" + currentId).serializeArray(), function (result) {
            if (result.code == web_status.SUCCESS) {
                window.location.href = ctx + "common/download?fileName=" + result.message + "&delete=" + true;
            } else {
                $.modal.alertError(result.message);
            }
            $.modal.closeLoading();
        });
    }

</script>
</body>
</html>